package com.zhong.gang.pda.ui.action.deliver;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.pda.R;
import com.zhong.gang.pda.databinding.ActivityDeliverBinding;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.pda.db.loction.LocationMessageUtils;
import com.zhong.gang.pda.ui.action.HuoBean;
import com.zhong.gang.pda.ui.action.HuoPersenter;
import com.zhong.gang.pda.ui.action.deliver.controller.BaseDeliverController;
import com.zhong.gang.pda.ui.action.deliver.controller.DeliverActionController;

/**
 * 发货
 */
public class DeliverAct extends ActBase<ActivityDeliverBinding> {
    private BaseDeliverController controller;
    private static final String ID = "ID";
    private static final String ISACTION = "ISACTION";
    private HuoPersenter persenter;
    public static final void openAct(Context context,int id,boolean isAction){
        Intent intent = new Intent(context,DeliverAct.class);
        intent.putExtra(ID,id);
        intent.putExtra(ISACTION,isAction);
        context.startActivity(intent);
    }

    @Override
    public boolean showLoading() {
        return true;
    }

    @Override
    public int LayoutRes() {
        return R.layout.activity_deliver;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public void initView() {
        controller = new DeliverActionController(DeliverAct.this, getIntent().getIntExtra(ID, 0));
        bind.sendCardView.setTitle("选择派车单");
        persenter = new HuoPersenter();
        bind.setAct(this);
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        persenter.getDetailData(this,getIntent().getIntExtra(ID,0),this.new ActCallBack<BaseDataBean<HuoBean>>() {
            @Override
            public void onResponse(BaseDataBean<HuoBean> data) throws Exception {
                super.onResponse(data);
                HuoBean huoBean = LocationMessageUtils.getIntent(DeliverAct.this).getData(data.getResult());
                if (data.getResult().getOrderSend() == null && huoBean != null)
                    data.getResult().setOrderSend(huoBean.getOrderSend());
                controller.setScalesMsg(data.getResult());
            }
        });
    }

    /**
     * 点击事件
     * @param view
     */
    public void onViewClicked(View view){
        if (controller instanceof DeliverActionController)
            ((DeliverActionController)controller).onViewClicked(view);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (controller instanceof DeliverActionController)
            ((DeliverActionController)controller).onActivityResult(requestCode,resultCode,data);
    }
}
